package utils;

import net.bytebuddy.agent.ByteBuddyAgent;
import net.bytebuddy.agent.builder.AgentBuilder;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.matcher.ElementMatchers;

/**
 * @author yutianhong
 * @version 1.0
 * @since 2025/5/27 21:19
 */
public class TimeAgent {
    public static void install(String className) {
        new AgentBuilder.Default()
                .type(ElementMatchers.named(className))
                .transform(
                        (builder, type, classLoader, module, protectionDomain) ->
                                builder.method(ElementMatchers.any())
                                        .intercept(MethodDelegation.to(TimingInterceptor.class))
                )
                .installOn(ByteBuddyAgent.install());
    }

    private TimeAgent() {
    }

}
